<?php 
include("admin_check.php");
include_once("../function.php");
include_once("../class/bonus_class.php");
include_once("../class/system_class.php");
include_once("../class/ulevel_class.php");
session_start();
header("Content-Type: text/html;charset=utf-8");
checkqx(2,6);
if ($_POST['button2']){
        $ymd=date('y-m-d');
        $date=strtotime($ymd);
        $week=date('w');
        $fristweeks =strtotime(date('Y-m-d ',strtotime( '+'. 1-$week .' days' )));
        $lastweeks =strtotime(date('Y-m-d 23:59:59',strtotime( '+'. 7-$week .' days' )));

        $admin=getMemberbyID(1);
        if($admin['ztime']<$date) {
            $mey1= $_POST['mey1'];
            $mey2= $_POST['mey2'];
            $mey3= $_POST['mey3'];
            $mey4= $_POST['mey4'];
            $mey5= $_POST['mey5'];
            //1
            $sql1 = "SELECT id FROM `member` WHERE ispay>0 and plevel2=1";
            $re11 = mysql_query($sql1);
            $num1 = mysql_num_rows($re11);
            //2
            $sql2 = "SELECT id FROM `member` WHERE ispay>0 and plevel2=2";
            $re2 = mysql_query($sql2);
            $num2 = mysql_num_rows($re2);
            //3
            $sql3 = "SELECT id FROM `member` WHERE ispay>0 and plevel2=3";
            $re3 = mysql_query($sql3);
            $num3 = mysql_num_rows($re3);
            //4
            $sql4 = "SELECT id FROM `member` WHERE ispay>0 and plevel2=4";
            $re4 = mysql_query($sql4);
            $num4 = mysql_num_rows($re4);
            //5
            $sql5 = "SELECT id FROM `member` WHERE ispay>0 and plevel2=5";
            $re5 = mysql_query($sql5);
            $num5 = mysql_num_rows($re5);
            ///


            $_bonus_cl = new bonus_class();
            $sql = "SELECT id,plevel2 FROM `member` WHERE ispay>0 and plevel2>0";
            $re = mysql_query($sql);
            while ($rs=mysql_fetch_assoc($re)){
                if($rs['plevel2']==1){
                    $_bonus_cl->yeji($rs['id'],$mey1,$num1,$date);
                }elseif($rs['plevel2']==2){
                    $_bonus_cl->yeji($rs['id'],$mey2,$num2,$date);
                }elseif($rs['plevel2']==3){
                    $_bonus_cl->yeji($rs['id'],$mey3,$num3,$date);
                }elseif($rs['plevel2']==4){
                    $_bonus_cl->yeji($rs['id'],$mey4,$num4,$date);
                }elseif($rs['plevel2']==5){
                    $_bonus_cl->yeji($rs['id'],$mey5,$num5,$date);
                }
                $_bonus_cl->b0bonus();
            }
            echo "<script language=javascript>alert('业绩分红发放完成.');window.location.href='admin_bonuslaiyuan.php'</script>";
        }else{
            echo "<script language=javascript>alert('本周已发放.');window.location.href='?'</script>";
        }
}
$_system=new system_class();
$_ulevel=new ulevel_class();
$system=$_system->system_right();
$_iul=$_ulevel->getulevelbyulevel(1);
$sql="select sum(lsk) as slsk from member where ispay>0 and id<>1";
$slsk=getOne($sql);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>清空数据库</title>
<link href="css/table.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
  <tr>
    <td align="center"><strong><font color="#FF0000">注意：结算奖金前请先做好数据备份</font></strong></td>
  </tr>
    <tr>
      <td align="center">区代理分红总收入的<?=$_iul['yl6']?>%<input name="mey1" type="text" id="mey1" value="<?=$slsk['slsk']*$_iul['yl6']/100?>"/></td>
    </tr>
    <tr>
      <td align="center">县代理分红总收入的<?=$_iul['yl7']?>%<input name="mey2" type="text" id="mey2" value="<?=$slsk['slsk']*$_iul['yl7']/100?>"/></td>
    </tr>
    <tr>
      <td align="center">市代理分红总收入的<?=$_iul['yl8']?>%<input name="mey3" type="text" id="mey3" value="<?=$slsk['slsk']*$_iul['yl8']/100?>"/></td>
    </tr>
    <tr>
      <td align="center">省代理分红总收入的<?=$_iul['yl9']?>%<input name="mey4" type="text" id="mey4" value="<?=$slsk['slsk']*$_iul['yl9']/100?>"/></td>
    </tr>
    <tr>
      <td align="center">股东分红总收入的<?=$_iul['yl10']?>%<input name="mey5" type="text" id="mey5" value="<?=$slsk['slsk']*$_iul['yl10']/100?>"/></td>
    </tr>
  <tr >
    <td align="center">

      <input name="button2" type="submit" class="btn2" id="button2" value="静态分红发放" onClick="{if(confirm('您确定要结算奖金吗?')){this.document.selform.submit();return true;}return false;}"/>
   </td>
  </tr>
</table>
</form>
</body>
</html>